package server.core;

import server.Container;
import server.Loader;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandler;

public class SimpleLoader implements Loader {
    private static final String WEB_ROOT = System.getProperty("user.dir") + File.separator + "webroot";
    private Container container = null;
    private static final URLClassLoader LOADER;
    static {
        String repository = "file:" + WEB_ROOT + File.separator;
        URL[] urls = new URL[1];
        URLStreamHandler streamHandler = null;
        try {
            urls[0] = new URL(null, repository, streamHandler);
        } catch (MalformedURLException e) {
            System.out.println("servlet加载器初始化出错");
            e.printStackTrace();
        }
        LOADER = new URLClassLoader(urls);
    }
    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    public ClassLoader getClassLoader() {
        return LOADER;
    }
}
